package com.example.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    // test
    private final String createTime = "createTime";
    private final String updateTime = "updateTime";

    @Override
    public void insertFill(MetaObject metaObject) {

        this.strictInsertFill(metaObject, createTime, ZonedDateTime.class,  ZonedDateTime.now(Clock.systemUTC()));
        this.strictInsertFill(metaObject, updateTime, ZonedDateTime.class,  ZonedDateTime.now(Clock.systemUTC()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, updateTime, ZonedDateTime.class,  ZonedDateTime.now(Clock.systemUTC()));
    }
}
